public class IsValidBST {
    // 判断是不是二叉搜索树
    // https://www.nowcoder.com/practice/a69242b39baf45dea217815c7dedb52b?tpId=295&tags=&title=&difficulty=0&judgeStatus=0&rp=0&sourceUrl=%2Fexam%2Foj%3Fpage%3D1%26tab%3DSQL%25E7%25AF%2587%26topicId%3D295
    private int prev;
    public boolean isValidBST (TreeNode root) {
        // write code here
        prev = Integer.MIN_VALUE;
        return inorder(root);
    }

    private boolean  inorder(TreeNode root) {
        if (root == null) {
            return true;
        }
        if (!inorder(root.left)) {
            return false;
        }
        if (root.val < prev) {
            return false;
        }
        prev = root.val;
        return inorder(root.right);
    }
}
